<template>
    <div>
        <a-modal
            :visible="handleModalVisible"
            :title="passObj.title"
            :maskClosable="false"
            :closable="true"
            :destroyOnClose="true"
            width="80%"
            :dialog-style="{ margin: '0 auto'}"
            wrapClassName=""
            @cancel="closeVisible"
            >
            <template slot="footer">
                <a-button key="back" @click="closeVisible">
                    取消
                </a-button>
                <a-button key="submit" type="primary" @click="onSubmit">
                    提交
                </a-button>
            </template>
            <a-form-model
                ref="ruleForm"
                :model="form"
                :rules="rules"
                layout="inline"
                class="internalControl-modal-form"
            >
                <a-form-model-item label="预算来源名称" prop="fyslymc">
                    <a-input v-model="form.fyslymc"/>
                    <!-- <compSelector
                        v-model="form.fyslymc"
                        :defaultValue="form.fyslymc"
                        :compType="typeSelect"
                        @selectHandleChange=""
                        dictionaryType=""/> -->
                </a-form-model-item>
                <a-form-model-item label="预算项目名称" prop="fysxmmc">
                    <a-input v-model="form.fysxmmc"/>
                </a-form-model-item>
                <a-form-model-item label="总指标" prop="fzzb">
                    <a-input-number v-model="form.fzzb" @change="fzzbChange" style="width:100%"/>
                </a-form-model-item>
                <a-form-model-item label="是否已完全拆分">
                    <a-select default-value="0" v-model="form.fsfywqcf">
                        <a-select-option value="1">
                            已拆分
                        </a-select-option>
                        <a-select-option value="0">
                            未拆分
                        </a-select-option>
                        <a-select-option value="2">
                            已拆分完成
                        </a-select-option>
                    </a-select>
                </a-form-model-item>
                <a-form-model-item label="指标摘要">
                    <a-input v-model="form.fzbzy"/>
                </a-form-model-item>
                <a-form-model-item label="在途计划金额">
                    <a-input-number :max="form.fzzb" v-model="form.fztjhje" style="width:100%"/>
                </a-form-model-item>
                <a-form-model-item label="已申请支付金额">
                    <a-input-number :max="form.fzzb" v-model="form.fysqzfje" style="width:100%"/>
                </a-form-model-item>
                <a-form-model-item label="已支付金额">
                    <a-input-number :max="form.fzzb" v-model="form.fyzfje" style="width:100%"/>
                </a-form-model-item>
                <a-form-model-item label="指标结余">
                    <a-input-number :max="form.fzzb" v-model="form.fzbjy" style="width:100%"/>
                </a-form-model-item>
                <!-- <a-form-model-item label="支出进度">
                    <a-input v-model="form.fzcjd"/>
                </a-form-model-item> -->
                <a-form-model-item label="功能分类名称">
                    <a-input v-model="form.fgnflmc"/>
                </a-form-model-item>
                <a-form-model-item label="部门经济分类名称">
                    <a-input v-model="form.fbmjjflmc"/>
                </a-form-model-item>
                <a-form-model-item label="政府经济分类名称">
                    <a-input v-model="form.fzfjjflmc"/>
                </a-form-model-item>
                <a-form-model-item label="指标来源名称">
                    <a-input v-model="form.fzblymc"/>
                </a-form-model-item>
                <a-form-model-item label="部门经济分类编码">
                    <a-input v-model="form.fbmjjflbm"/>
                </a-form-model-item>
                <a-form-model-item label="是否政府采购">
                  <a-radio-group name="radioGroup" v-model="form.fsfzfcg">
                      <a-radio value="是">
                        是
                      </a-radio>
                      <a-radio value="否">
                        否
                      </a-radio>
                    </a-radio-group>
                </a-form-model-item>
            </a-form-model>
        </a-modal>
    </div>
</template>
<script>
import compSelector from '@/components/compSelector/compSelector'
import {typeInput, typeNumber, typeSelect, typeCheckbox, typeRadio, } from '@/components/compSearchCriteria/ContractType'
import { add,edit,} from './service/index'
import moment from 'moment'
export default {
    props:{
        passObj:{
            type:[Array,Object],
            default: () => {},
            required:false
        },
        linkName:{
            type:String,
            default:'',
            required:false,
        },
    },
    components:{
        compSelector
    },
    data() {
        return {
            moment:moment,
            handleModalVisible: false,
            form: {},
            kongForm: {},
            labelCol: { span: 8 },
            wrapperCol: { span: 16 },
            typeSelect:typeSelect,
            form: {
                fsfzfcg: '',
                fbmjjflbm: "",
                fbmjjflmc: "",
                fgnflbm: "",
                fgnflmc: "",
                fsfywqcf: null,
                fyslymc: "",
                fysqzfje: 0,
                fysxmmc: "",
                fyzfje: 0,
                fzbjy: 0,
                fzblymc: "",
                fzbzy: "",
                fzcjd: "0.00",
                fzcxmlbbm: "",
                // fzcxmlbmc: "",
                fzfjjflbm: "",
                fzfjjflmc: "",
                fztjhje: 0,
                fzzb: 0,
                id: "",
            },
            rules: {
                fyslymc: [{ required: true, message: '请输入预算来源名称', trigger: 'blur' }],
                fysxmmc: [{ required: true, message: '请输入预算项目名称', trigger: 'blur' }],
                fzzb: [{ required: true, message: '请输入总指标', trigger: 'blur' }],
            },
        }
    },
    mounted() {
        this.kongForm = JSON.parse(JSON.stringify(this.form))
    },
    watch: {
        passObj(newval,oldVal){
            //console.log(newval)
            if(newval.valueData){
                this.form = {...newval.valueData}
            }
        },
    },
    methods: {
        // 右上角关闭后的回调
        closeVisible(e){
            this.$emit('success')
            this.handleModalVisible = false
            this.form = {...this.kongForm}
            this.$refs.ruleForm.resetFields();
        },
        //
        fzzbChange(){
            this.form.fzbjy = this.form.fzzb
        },
        onSubmit() {
            this.$refs.ruleForm.validate(valid => {
                if (valid) {
                    let data = this.form
                    if(this.passObj.valueData){
                        edit(data).then(res => {
                            if(res.code == 200){
                                this.$message.success(res.message)
                                this.closeVisible()
                            } else {
                                this.$message.warning(res.message)
                            }
                        })
                    } else {
                        add(data).then(res => {
                            if(res.code == 200){
                                this.$message.success(res.message)
                                this.closeVisible()
                            } else {
                                this.$message.warning(res.message)
                            }
                        })
                    }
                } else {
                    //console.log('error submit!!');
                    return false;
                }
            });
        },
    },
}
</script>
<style>
    @import url('../../css/internal-control.css');
</style>
